using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using DTO;
using System.Configuration;
using System.Data;
namespace DAL
{
    public class tbCauThuDAL
    {
        public static tbCauThuDAL CreatetbCauThuDAL()
        { 
            return new tbCauThuDAL(); 
        }

        private SqlConnection cn = null;
    
        public tbCauThuDAL()
        {
                cn = new SqlConnection(ConfigurationManager.ConnectionStrings["strConnection"].ConnectionString);
                cn.Open();
        }

        public tbCauThuDAL(tbBangXepHangDAL bxh )
        {
                this.cn = new SqlConnection(ConfigurationManager.ConnectionStrings["strConnection"].ConnectionString);
           
         this.cn.Open();
        }
        public void Insert(tbCauThuDTO cauThu)
        {
            SqlCommand cmd = new SqlCommand("tbCauThu_Insert", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@hotencauthu", cauThu.HoTenCauThu);
            cmd.Parameters.AddWithValue("@gioitinh", cauThu.GioiTinh);
            cmd.Parameters.AddWithValue("@ngaysinh", cauThu.NgaySinh);
            cmd.Parameters.AddWithValue("@noisinh", cauThu.NoiSinh);
            cmd.Parameters.AddWithValue("@diachi", cauThu.DiaChi);
            cmd.Parameters.AddWithValue("@quoctich", cauThu.QuocTich);
            cmd.Parameters.AddWithValue("@soao", cauThu.SoAo);
            cmd.Parameters.AddWithValue("@chieucao", cauThu.ChieuCao);
            cmd.Parameters.AddWithValue("@cannang", cauThu.CanNang);
            cmd.Parameters.AddWithValue("@vitri", cauThu.ViTri);
            cmd.Parameters.AddWithValue("@doihinh", cauThu.DoiHinh);
            cmd.Parameters.AddWithValue("@caulacbo", cauThu.CauLacBo);
            cmd.Parameters.AddWithValue("@ghichu", cauThu.GhiChu);
            cmd.ExecuteNonQuery();
        }
        public void Update(tbCauThuDTO cauThu)
        {
            SqlCommand cmd = new SqlCommand("tbCauThu_Update", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@macauthu", cauThu.MaCauThu);
            cmd.Parameters.AddWithValue("@hotencauthu", cauThu.HoTenCauThu);
            cmd.Parameters.AddWithValue("@gioitinh", cauThu.GioiTinh);
            cmd.Parameters.AddWithValue("@ngaysinh", cauThu.NgaySinh);
            cmd.Parameters.AddWithValue("@noisinh", cauThu.NoiSinh);
            cmd.Parameters.AddWithValue("@diachi", cauThu.DiaChi);
            cmd.Parameters.AddWithValue("@quoctich", cauThu.QuocTich);
            cmd.Parameters.AddWithValue("@soao", cauThu.SoAo);
            cmd.Parameters.AddWithValue("@chieucao", cauThu.ChieuCao);
            cmd.Parameters.AddWithValue("@cannang", cauThu.CanNang);
            cmd.Parameters.AddWithValue("@vitri", cauThu.ViTri);
            cmd.Parameters.AddWithValue("@doihinh", cauThu.DoiHinh);
            cmd.Parameters.AddWithValue("@caulacbo", cauThu.CauLacBo);
            cmd.Parameters.AddWithValue("@ghichu", cauThu.GhiChu);
            cmd.ExecuteNonQuery();
        }
        public void Delete(int iD)
        {
            SqlCommand cmd = new SqlCommand("tbCauThu_Delete", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@macauthu", iD);
            cmd.ExecuteNonQuery();
        }
    }
}
